Skip to content

feat(dashboard): traffic-aware latest values for cw_traffic2 - #80

Merged
CropWatchDevelopment merged 1 commit into
masterfrom
develop
Jul 27, 2026
Merged

CropWatchDevelopment merged 1 commit into
masterfrom
develop

Conversation

@CropWatchDevelopment

Copy link
Copy Markdown
Owner

Dashboard cards for AI-camera (cw_traffic2) devices showed all zeros: the table is an hourly accumulator — one row per (dev_eui, traffic_hour, line_number) upserted by an increment RPC that never bumps created_at — so ORDER BY created_at DESC LIMIT 1 returned an arbitrary line's freshly created, near-empty bucket.

  • fetchLatest/getLatest now branch for cw_traffic2 and return today's totals per count column, summed across all hour buckets and detection lines (local day in Asia/Tokyo, matching TrafficService)
  • getLatest returns an aggregated pseudo-row (no id/line_number) with the latest traffic_hour
  • Zero rows today → zero totals with the freshness stamp of the most recent bucket
  • Timezone helpers moved from TrafficService into TimezoneFormatterService for reuse
  • All other tables keep the existing latest-row path — backward compatible

Deploy this before the frontend traffic redesign (CropWatch PR) — frontend-first leaves the dashboard zeros in place until this ships.

🤖 Generated with Claude Code

…traffic2

cw_traffic2 is an hourly accumulator: one row per (dev_eui, traffic_hour,
line_number), upserted by an increment RPC that never bumps created_at, so
ORDER BY created_at DESC LIMIT 1 returned an arbitrary line's freshly
created (near-empty) bucket — dashboard cards showed zeros.

- fetchLatest/getLatest now branch for cw_traffic2: sum every count column
  across all of today's hour buckets and detection lines (local day in
  Asia/Tokyo, matching TrafficService's default); getLatest returns an
  aggregated pseudo-row (no id/line_number) with the latest traffic_hour
- Zero rows today reports zero totals with the freshness stamp of the most
  recent bucket (a quiet day is legitimately 0, not "no data")
- Move localMidnightToUtc/toLocalDateString/getTimezoneOffsetMs from
  TrafficService into TimezoneFormatterService for reuse; DashboardModule
  imports CommonModule

Other tables keep the existing latest-row path — backward compatible.
Deploy before the frontend traffic redesign (frontend-first leaves
dashboard zeros until this ships).

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api Ready Ready Preview, Comment Jul 27, 2026 9:36am

Request Review

@CropWatchDevelopment
CropWatchDevelopment merged commit 412ef60 into master Jul 27, 2026
5 checks passed

This branch was successfully deployed

1 active and 1 inactive deployments
Production — e4c5554e Deployed Jul 27, 2026 by CropWatchDevelopment via build #13
Preview — e4c5554e Deployed Jul 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant